package com.blog.admin;

import com.blog.model.*;
import com.jfinal.plugin.activerecord.Page;


/**
 * Created by ${wangjian} on 2017/9/7.
 */
public class AdminService {

    private static final Blog dao = Blog.dao;

    /**
     * 分页获取blog
     *
     * @param pageNumber
     * @return
     */
    public Page<Blog> paginate(int pageNumber) {
        return dao.paginate(pageNumber);
    }

    /**
     * 添加blog
     *
     * @param title
     * @param content
     * @param keywords
     * @return
     */
    public void addContent(String title, String content, String digest, String keywords, String alias, long albumId) {
        Blog blog = new Blog();
        blog.setTitle(title);
        blog.setContent(content);
        blog.setDigest(digest);
        blog.setKeywords(keywords);
        blog.setAlias(alias);
        blog.setAlbumId(albumId);
        blog.save();
    }

    /**
     * 根据logId
     *
     * @param logId
     * @return
     */
    public Blog queryContent(int logId) {
        return dao.findById(logId);
    }

    /**
     * 查询所有album
     *
     * @param id
     * @return
     */
    public Album queryAlbum(int id) {
        return new Album().getById(id);
    }

    /**
     * 分页获取Album
     *
     * @param pageNumber
     * @return
     */
    public Page<Album> page(int pageNumber) {
        return new Album().paginate(pageNumber);
    }

    /**
     * 保存图片
     *
     * @param message
     * @param suffix
     * @param base64
     * @return
     */
    public long addImg(String message, String suffix, String base64) {
        Album album = new Album();
        album.setMessage(message);
        album.setSuffix(suffix);
        album.setBase64(base64);
        album.save();
        return album.getId().longValue();
    }

    /**
     * 分页获取idea
     *
     * @param pageNumber
     * @return
     */
    public Page<Idea> paginateIdea(int pageNumber) {
        return new Idea().paginateIdea(pageNumber);
    }

    /**
     * 添加idea
     *
     * @param idea
     */
    public void addIdea(String idea) {
        Idea ideaOne = new Idea();
        ideaOne.setIdea(idea);
        ideaOne.save();
    }

    /**
     * 查询所有idea
     *
     * @param id
     * @return
     */
    public Idea queryIdea(int id) {
        return new Idea().getByIdea(id);
    }

    /**
     * 分页获取idea
     *
     * @param pageNumber
     * @return
     */
    public Page<Message> paginateMessage(int pageNumber) {
        return new Message().paginate(pageNumber);
    }

    public Message queryMessage(int id){
        return new Message().findById(id);
    }
}
